package com.example.mapping.sevice;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.mapping.constant.Constants;
import com.example.mapping.convert.FieldMappingConvert;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mapping.mapper.FieldMappingMapper;
import com.example.mapping.domain.FieldMapping;
import org.springframework.util.CollectionUtils;

/**
 * @author baoyoujia
 */
@Service
public class FieldMappingService extends ServiceImpl<FieldMappingMapper, FieldMapping> {

    @Autowired
    private FieldMappingConvert fieldMappingConvert;

    public int insertSelective(FieldMapping fieldMapping) {
        return baseMapper.insertSelective(fieldMapping);
    }

    public int updateByPrimaryKeySelective(FieldMapping fieldMapping) {
        return baseMapper.updateByPrimaryKeySelective(fieldMapping);
    }

    public int updateBatch(List<FieldMapping> list) {
        return baseMapper.updateBatch(list);
    }

    public int batchInsert(List<FieldMapping> list) {
        return baseMapper.batchInsert(list);
    }

    public List<FieldMapping> getFieldMappingByFlowId(Long flowId) {
        LambdaQueryWrapper<FieldMapping> fieldMappingLambdaQueryWrapper = new LambdaQueryWrapper<FieldMapping>().eq(FieldMapping::getFlowId, flowId).in(FieldMapping::getSysDelete, Constants.Number.INT_0, Constants.Number.INT_1);
        return list(fieldMappingLambdaQueryWrapper);
    }

    public List<FieldMapping> getFieldMappingByIds(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return Lists.newArrayList();
        }
        LambdaQueryWrapper<FieldMapping> fieldMappingLambdaQueryWrapper = new LambdaQueryWrapper<FieldMapping>().in(FieldMapping::getId, ids).in(FieldMapping::getSysDelete, Constants.Number.INT_0, Constants.Number.INT_1);
        return list(fieldMappingLambdaQueryWrapper);
    }

    public List<FieldMapping> getFieldMappingByFlowIds(List<Long> flowIds) {
        if (CollectionUtils.isEmpty(flowIds)) {
            return Lists.newArrayList();
        }
        LambdaQueryWrapper<FieldMapping> fieldMappingLambdaQueryWrapper = new LambdaQueryWrapper<FieldMapping>().eq(FieldMapping::getFlowId, flowIds).in(FieldMapping::getSysDelete, Constants.Number.INT_0, Constants.Number.INT_1);
        return list(fieldMappingLambdaQueryWrapper);
    }
}
